<template>
    <!-- mine/pages/messagenotification/messagenotification.wxml -->
    <view class="containers" :style="objColor">
        <view class="containers-in" v-for="(item, index) in peizhi" :key="index">
            <view style="height: auto">
                <view class="containers-title">{{ item.messageName }}</view>
                <view class="containers-sm">{{ item.messageDesc }}</view>
            </view>
            <view style="height: auto">
                <u-switch v-model="checked"  asyncChange @change="onChange" :size="30" class="kaiguan" v-if="index == 0"/>
				<u-switch v-model="checked1"  asyncChange @change="onChange1" :size="30" class="kaiguan" v-if="index == 1"/>
            </view>
        </view>   
    </view>
</template>

<script>
'use strict';
// import vanSwitch from '@vant/weapp/switch/index';

// exports.__esModule = true; // mine/pages/messagenotification/messagenotification.ts

var https_1 = require('./../../../api/https.js');
export default {
    components: {
        // vanSwitch
    },
    data() {
        return {
            checked: true,
            checked1: true,
            peizhi: []
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {},
    onShow: function () {
        this.messagePushlist();
    },
    methods: {
        // 充电结束提醒
        onChange: function (_a) {
            var detail = _a; // 需要手动对 checked 状态进行更新
            this.checked= detail
            var peizhi = this.peizhi;
            var messageId = peizhi[0].messageId;
            https_1
                .messagePushsetting({
                    messageId: messageId,
                    status: detail == true ? 1 : 0,
                    channelCode: 3,
                    openId: uni.getStorageSync('openid'),
                    messageType: 1 //1:充电结束提醒　4:充电满前提醒
                })
                .then(function (res) {
                    // console.log(res)
                });
        },

        //   电量充满前提醒
        onChange1: function (_a) {
            var detail = _a; // 需要手动对 checked 状态进行更新
            this.checked1= detail
            var peizhi = this.peizhi;
            var messageId = peizhi[1].messageId;
            https_1
                .messagePushsetting({
                    messageId: messageId,
                    status: detail == true ? 1 : 0,
                    channelCode: 3,
                    openId: uni.getStorageSync('openid'),
                    messageType: 4 //1:充电结束提醒　4:充电满前提醒
                })
                .then(function (res) {
                    // console.log(res)
                });
        },

        messagePushlist: function () {
            var that = this;
            https_1.messagePushlist({}).then(function (res) {
                var peizhi = res.data;
                that.peizhi= peizhi

                if (peizhi[0].status == 1) {
                    that.checked= true
                } else {
                    that.checked= false
                }

                if (peizhi[1].status == 1) {
                    that.schecked1= true
                } else {
                    that.checked1= false
                }
            });
        }
    }
};
</script>
<style lang="less">
@import url('./messagenotification.less');
</style>
